load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")
load("//bazel:fuzz_testing.bzl", "DEFAULT_RUSTC_FLAGS_FOR_FUZZING")
load("//bazel:prost.bzl", "generated_files_check")

package(default_visibility = ["//visibility:public"])

filegroup(
    name = "protos",
    srcs = glob(["proto/**"]),
)

rust_library(
    name = "base_types",
    srcs = glob([
        "src/**",
    ]),
    crate_features = select({
        "//bazel:fuzzing_code_enabled": ["fuzzing_code"],
        "//conditions:default": [],
    }),
    crate_name = "ic_base_types",
    proc_macro_deps = [
        # Keep sorted.
        "@crate_index//:strum_macros",
    ],
    rustc_flags = select({
        "//bazel:fuzzing_code_enabled": DEFAULT_RUSTC_FLAGS_FOR_FUZZING,
        "//conditions:default": [],
    }),
    version = "0.9.0",
    deps = [
        # Keep sorted.
        "//packages/ic-heap-bytes",
        "//rs/crypto/sha2",
        "//rs/phantom_newtype",
        "//rs/protobuf",
        "@crate_index//:byte-unit",
        "@crate_index//:bytes",
        "@crate_index//:candid",
        "@crate_index//:comparable",
        "@crate_index//:hex",
        "@crate_index//:prost",
        "@crate_index//:serde",
        "@crate_index//:serde_bytes",
        "@crate_index//:strum",
    ] + select({
        "//bazel:fuzzing_code_enabled": ["@crate_index//:arbitrary"],
        "//conditions:default": [],
    }),
)

rust_test(
    name = "base_types_test",
    crate = ":base_types",
    proc_macro_deps = [
        # Keep sorted.
        "@crate_index//:strum_macros",
    ] + [
        # Keep sorted.
        "@crate_index//:proptest-derive",
    ],
    deps = [
        # Keep sorted.
        "//rs/crypto/sha2",
        "//rs/phantom_newtype",
        "//rs/protobuf",
        "@crate_index//:assert_matches",
        "@crate_index//:byte-unit",
        "@crate_index//:bytes",
        "@crate_index//:candid",
        "@crate_index//:comparable",
        "@crate_index//:hex",
        "@crate_index//:proptest",
        "@crate_index//:prost",
        "@crate_index//:serde",
        "@crate_index//:serde_bytes",
        "@crate_index//:serde_cbor",
        "@crate_index//:strum",
    ] + select({
        "//bazel:fuzzing_code_enabled": ["@crate_index//:arbitrary"],
        "//conditions:default": [],
    }),
)

generated_files_check(
    name = "check_generated_files",
    srcs = ["tests/check_generated_files.rs"],
    data = glob([
        "src/gen/**",
    ]) + [":protos"],
    manifest_dir = "rs/types/base_types",
    deps = [
        # Keep sorted.
        "//rs/test_utilities/compare_dirs",
        "//rs/types/base_types/protobuf_generator:lib",
        "@crate_index//:tempfile",
    ],
)
